//
// Created by Administrator on 2018/7/29.
//


#include "com_zyf_jni_hello_HelloWorld.h"

#include <android/log.h>
#define LOG_TAG "System.out.c"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)

JNIEXPORT jstring JNICALL c_hello
  (JNIEnv *env, jclass jobj){

    LOGI("c_hello");
    return (*env)->NewStringUTF(env,"HelloWorld 我是用jni调用出来的字符串");
  }


JNIEXPORT jint JNICALL c_add
  (JNIEnv *evn, jobject jobj, jint a, jint b){
    LOGI("c_add");
    return a+b;
  }

static const JNINativeMethod methods[] = {
        {"helloworld","()Ljava/lang/String;",(void *)c_hello},
        {"add","(II)I",(void *)c_add},
};

jint JNICALL JNI_OnLoad(JavaVM * jvm,void * reserved){
    JNIEnv *env;
    jclass cls;
    if ((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_4)) {
        return JNI_ERR; /* JNI version not supported */
    }
    cls = (*env)->FindClass(env, "com/zyf/jni_hello/HelloWorld");
    if (cls == NULL) {
        return JNI_ERR;
    }

    (*env)->RegisterNatives(env, cls, methods,2);

    return JNI_VERSION_1_4;
}
